﻿//-----------------------------------------------------------------------
// <copyright file="AdminWindow.xaml.cs" company="FER">
//     Copyright (c) All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace NMBP_odb
{
    using System;
    using System.Windows;
    using GalaSoft.MvvmLight.Messaging;
    using NMBP.Models;
    using NMBP.View;
    using NMBP.View.ViewModel;

    /// <summary>
    /// Interaction logic for AdminWindow.xaml
    /// </summary>
    public partial class AdminWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the AdminWindow class
        /// </summary>
        public AdminWindow()
        {
            InitializeComponent();

            Messenger.Default.Register<Worker>(
                this,
                "OpenEditCustomerWindow",
                (msg) =>
                    {
                        EditCustomerFromAdminWindow editCustomerWindow = new EditCustomerFromAdminWindow();
                        Messenger.Default.Send<Worker>(msg, "InitializeEditCustomerFromAdmin");
                        editCustomerWindow.Show();
                        this.Close();
                    });

            Messenger.Default.Register<Worker>(
                this,
                "OpenEditWorkerWindow",
                (msg) =>
                    {
                        EditWorkerWindow editWorkerWindow = new EditWorkerWindow();
                        Messenger.Default.Send<Worker>(msg, "InitializeEditWorker");
                        editWorkerWindow.Show();
                        this.Close();
                    });

            this.Closing += ((s, e) =>
                                 {
                                     Messenger.Default.Unregister(this);
                                     ViewModelLocator.ClearAdminViewModel();
                                 });
        }
    }
}
